home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
632
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
1KB
Path: news.compuserve.com!newsmaster
From: JamesCurran@CIS.CompuServe.com (James M. Curran)
Newsgroups: comp.std.c
Subject: Re: Restrictions on qsort compare function?
Date: Fri, 22 Mar 1996 21:07:02 GMT
Organization: CompuServe Incorporated
Message-ID: <4iv4rf$frk@dub-news-svc-3.compuserve.com>
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com> <4iukhc$5nr@rdsunx.crd.ge.com>
NNTP-Posting-Host: dd75-092.compuserve.com
X-Newsreader: Forte Free Agent 1.0.82
In <<4iukhc$5nr@rdsunx.crd.ge.com>>,
volpe@bart.crd.ge.com (Christopher R. Volpe) wrote:
>Alternatively, how about this:
> return ((signed int) ((unsigned int)a - (unsigned int)b));
That won't work. First consider a=-32 and b = 31, which, with 16-bit
ints becomes:
(signed int) ( (unsigned int) -32 - (unsigned int) 31 )
== (signed int) 65504 - 31
== (signed int) 65473
== -63 (a negative value, as it should)
Now, multiple each value by 1000. Since the relationship is the same,
we should again get a negative number, however:
(signed int) ( (unsigned int) -32000 - (unsigned int) 31000 )
== (signed int) ( 33536 - 31000)
== (signed int) ( 2536)
== 2536 (a positiove value)